<%@ page contentType="text/html;charset=UTF-8" %>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Positions</title>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><g:link class="home" controller="event" action="home">Home</g:link></span>

           
            <span class="menuButton"><g:link controller="user" action="logout">Logout</g:link></span>
        </div>

        <div class="body">
            <h1>Events</h1>
<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
<table border="0">
    <tr><td>Event Name: </td><td>${event.name}</td></tr>
    <tr><td>Event Description</td><td>${event.description} </td></tr>
    <tr><td>Event Date</td><td><g:formatDate format="MM-dd-yyyy" date="${event.date}"/> </td></tr>
    <tr><td>Event Coordinator </td><td>${event.coordinator.name}</td></tr>
</table>
   
            <h1>Event's Positions</h1>

    <g:if test="${event.positiones.size()<1}">
        No position created for this event yet.
    </g:if>
    <g:else>
    <table>
    <th>Name</th><th>Description</th><th>Number of Positions Available</th><th></th><th>Currently Signed Up Volunteers</th>
    <g:each in="${event.positiones}" var="positione">
        <tr>
            <td>${positione.name}</td>
            <td>${positione.description}</td>
            <%def numberOfPositionAvailable=positione.numUnfilledposition()%>

            <td>${numberOfPositionAvailable}</td>
            <td>
                <g:if test="${numberOfPositionAvailable > 0}">
                    <g:form controller="positionRegistration" id="${positione.id}"><g:actionSubmit value="Sign me up" action="create"/></g:form>
                </g:if>
            </td>
            <td>
                <g:each in="${positione.registrations}" var="registration">
                ${registration.user.name}<br />
                </g:each>
             </td>
        </tr>
    </g:each>
</table>
    </g:else>        
        </div>
    </body>
</html>